<template>
	<view class=" block">
		<u-popup :show="show" @close="close" mode="center" :round="15">
			<view class="mainpadding">
				<view class="xiaohei bigtext fonweight textcenter">添加设备</view>
				<input class="input margin_top6" type="number" placeholder="请输入注册码" v-model="zccode">
				<input class="input margin_top" type="text" placeholder="请输入设备名称" v-model="userset_name">
				<view class="flexcenter margin_top6">
					<view class="quxibtn flexcenter margin_right3" @click="close">取消</view>
					<view class="quedbtn flexcenter" @click="submit()">确定</view>
				</view>
			</view>
		</u-popup>
		<image class="smbicon" src="../../static/image/system/smtj.png" mode="" @click="scanbarCode()"></image>
		<view class="dingwei margin_top" @click="show = true">
			<image class="smbicon" src="../../static/image/system/sdtj.png" mode=""></image>
			<view class="" style="position: absolute; top: 46rpx;left: 46rpx;">
				<view class="xiaozi sanshier fonweight">手动添加</view>
				<view class="xiaozi" style="font-size: 20rpx; margin-top: 27rpx;">设备已连接网络，手动填写注册码绑定账户</view>
			</view>
		</view>

	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				zccode:"",
				userset_name:"",
			}
		},
		methods: {
			scanbarCode() {
				let that = this
				uni.scanCode({
					success: function (res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						that.show = true
						that.zccode = res.result
					}
				});
			
			},
			submit(){
				if(this.zccode==""){
					httpRequest.toast("请输入注册码")
					return false
				}
				if(this.userset_name==""){
					httpRequest.toast("请输入设备名称")
					return false
				}
				uni.showLoading({
					mask:true,
					title:"请稍后"
				})
				
				httpRequest.request('/api/sbcl/addSb', 'GET', {
					userset_name:this.userset_name,
					zccode:this.zccode
				}).then(res => {
					uni.hideLoading()
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.zccode=""
						this.userset_name=""
						this.close()
					}
					
				})
			},
			close() {
				this.show = false
				// console.log('close');
			}
		}
	}
</script>

<style lang="scss" scoped>
	.input {
		padding: 18rpx 30rpx;
		background: #F9F9F9;
		border-radius: 18rpx 18rpx 18rpx 18rpx;
	}

	.block {
		padding: 100rpx 50rpx 30rpx;
	}

	.smbicon {
		width: 100%;
		height: 196rpx;
	}
</style>